package com.frxuexi.park2301.my

import android.provider.ContactsContract.RawContacts.Data
import android.util.Log
import android.view.View
import androidx.databinding.DataBindingUtil
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.frxuexi.lib_base.entity.MyApporve
import com.frxuexi.lib_base.entity.MyParkBeanItem
import com.frxuexi.lib_base.entity.NewsBeanItem
import com.frxuexi.lib_base.entity.VisitBeanItem
import com.frxuexi.park2301.R
import com.frxuexi.park2301.databinding.ItemMynewsBinding
import com.frxuexi.park2301.databinding.ItemMyparkBinding
import com.frxuexi.park2301.databinding.ItemMyvisitBinding

class MyApproveAdapter:BaseMultiItemQuickAdapter<MyApporve,BaseViewHolder>(){
    init {
        addItemType(0,R.layout.item_mypark)
        addItemType(1,R.layout.item_myvisit)
        addItemType(2,R.layout.item_mynews)
    }

    override fun onItemViewHolderCreated(viewHolder: BaseViewHolder, viewType: Int) {
        super.onItemViewHolderCreated(viewHolder, viewType)
        DataBindingUtil.bind<ItemMyparkBinding>(viewHolder.itemView)
//        DataBindingUtil.bind<ItemMyvisitBinding>(viewHolder.itemView)
//        DataBindingUtil.bind<ItemMynewsBinding>(viewHolder.itemView)
    }
    override fun convert(helper: BaseViewHolder, item: MyApporve) {

        if(item.itemType==0){
            val parkBinding = DataBindingUtil.getBinding<ItemMyparkBinding>(helper.itemView)
            val bean=item as MyParkBeanItem
            Log.i("===",bean.toString())
            parkBinding?.bean=bean
            parkBinding!!.parkStatus.apply {
                when(item.status){
                    0->{
                        setText("待审核")
                        setTextColor(helper.itemView.context.getColor(com.frxuexi.lib_base.R.color.orange))
                        setBackgroundResource(com.frxuexi.lib_base.R.drawable.shape_weihu)
                        parkBinding.parkGroup.visibility=View.VISIBLE
                    }
                    1->{
                        setText("已通过")
                        setTextColor(helper.itemView.context.getColor(com.frxuexi.lib_base.R.color.green))
                        setBackgroundResource(com.frxuexi.lib_base.R.drawable.shape_status)
                        parkBinding.parkGroup.visibility=View.GONE
                    }
                    -1->{
                        setText("已拒绝")
                        setTextColor(helper.itemView.context.getColor(com.frxuexi.lib_base.R.color.redfont))
                        setBackgroundResource(com.frxuexi.lib_base.R.drawable.shape_solid_red)
                        parkBinding.parkGroup.visibility=View.GONE
                    }
                }
            }
        }else if(item.itemType==1){
            val binding = DataBindingUtil.getBinding<ItemMyvisitBinding>(helper.itemView)
            val bean=item as VisitBeanItem
            binding?.bean=bean
            binding!!.visitStatus.apply {
                when(item.visitStatus){
                    "待审核"->{
                        setTextColor(helper.itemView.context.getColor(com.frxuexi.lib_base.R.color.orange))
                        setBackgroundResource(com.frxuexi.lib_base.R.drawable.shape_weihu)
                        binding.visitGroup.visibility=View.VISIBLE
                    }
                    "已完成"->{
                        setTextColor(helper.itemView.context.getColor(com.frxuexi.lib_base.R.color.blue))
                        setBackgroundResource(com.frxuexi.lib_base.R.drawable.shape_zhanyong)
                        binding.visitGroup.visibility=View.GONE
                    }
                    "已通过"->{
                        setTextColor(helper.itemView.context.getColor(com.frxuexi.lib_base.R.color.green))
                        setBackgroundResource(com.frxuexi.lib_base.R.drawable.shape_status)
                        binding.visitGroup.visibility=View.GONE
                    }
                    "驳回"->{
                        setTextColor(helper.itemView.context.getColor(com.frxuexi.lib_base.R.color.redfont))
                        setBackgroundResource(com.frxuexi.lib_base.R.drawable.shape_solid_red)
                        binding.visitGroup.visibility=View.GONE
                    }
                }
            }

        }else{
            val binding = DataBindingUtil.getBinding<ItemMynewsBinding>(helper.itemView)
            val bean=item as NewsBeanItem
            binding?.bean=bean
        }
    }
}